/* *****************************************************************************************************
 * Copyright 2009. Dbwebx Group
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 * *****************************************************************************************************
 */
package org.dbwebx.service.dao.impl;

import org.dbwebx.domain.SourceNode;

import org.dbwebx.service.dao.SourceNodeService;
import org.dbwebx.service.dao.impl.base.BaseService;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * The {@link SourceNodeService} implementation. <br>
 * Provides methods for the {@link SourceNode} management.
 * 
 * @author Izzet_Mustafayev
 * 
 */
@SuppressWarnings("unchecked")
@Repository("sourceNodeService")
@Transactional
public class SourceNodeServiceImpl extends BaseService implements
		SourceNodeService {
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.dbwebx.service.dao.SourceNodeService#list()
	 */
	public List<SourceNode> list() {
		List<SourceNode> sourceNodes = new ArrayList<SourceNode>();
		List<org.dbwebx.persistence.SourceNode> sourceNodeEntities;
		sourceNodeEntities = em.createQuery("FROM SourceNode").getResultList();

		sourceNodes = mapList(sourceNodeEntities, SourceNode.class);

		return sourceNodes;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.dbwebx.service.dao.SourceNodeService#persist(org.dbwebx.persistence.
	 * Project)
	 */
	public void persist(final SourceNode sourceNode) {
		em.merge(dozerMapper.map(sourceNode,
				org.dbwebx.persistence.SourceNode.class));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.dbwebx.service.dao.SourceNodeService#find(java.lang.String)
	 */
	public SourceNode find(final String sourceNodeName) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.dbwebx.service.dao.SourceNodeService#load(java.lang.Long)
	 */
	public SourceNode load(final Long sourceNodeId) {
		SourceNode sourceNode = null;

		if (sourceNodeId > 0) {
			org.dbwebx.persistence.SourceNode loadedSourceNode = em.find(
					org.dbwebx.persistence.SourceNode.class, sourceNodeId);
			if (null != loadedSourceNode) {
				sourceNode = dozerMapper
						.map(loadedSourceNode, SourceNode.class);
			}
		}

		return sourceNode;
	}
}
